package com.jingyi.web.controller.wechat;

import com.jingyi.common.annotation.Anonymous;
import com.jingyi.common.config.JingYiConfig;
import com.jingyi.common.core.controller.BaseController;
import com.jingyi.common.core.domain.AjaxResult;
import com.jingyi.common.utils.file.FileUploadUtils;
import com.jingyi.common.utils.file.MimeTypeUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


/**
 * 医疗记录图片信息
 *
 * @author jingyi
 */
@RestController
@RequestMapping("/wxchat/photo")
public class PhotoController extends BaseController {
    /**
     * 图片上传
     */
    @Anonymous
    @PostMapping("/uploadImage")
    public AjaxResult uploadImage(@RequestParam("file") MultipartFile file) throws Exception
    {
        if (!file.isEmpty())
        {
            String imgPath = FileUploadUtils.upload(JingYiConfig.getUploadPath(), file, MimeTypeUtils.IMAGE_EXTENSION);
            imgPath = JingYiConfig.getPrefix() + imgPath;
            return AjaxResult.success("成功",imgPath);
        }
        return error("上传图片异常，请联系管理员");
    }
}
